﻿@using Orchard.Mvc.Html;
@using Orchard.UI.Resources;
@using Orchard;
@using Orchard.Caching;
@using EMS.PageTitleOverride.Services;
@using EMS.PageTitleOverride.Models;

@{
    RegisterLink(new LinkEntry {Type = "image/x-icon", Rel = "shortcut icon", Href = Url.Content("~/modules/orchard.themes/Content/orchard.ico")});
    Script.Include("html5.js").UseCondition("lt IE 9").AtHead();

    string title = Convert.ToString(Model.Title);
    
    IPageTitleOverrideService _pageTitleOverrideService = new PageTitleOverrideService(WorkContext);
    bool isPageTitleSiteNameLast = _pageTitleOverrideService.GetIsPageTitleSiteNameLast();
    bool isPageTitleHideSiteName = _pageTitleOverrideService.GetIsPageTitleHideSiteName();
    string pageTitle = _pageTitleOverrideService.GetPageTitleOverride();
    
    if (!String.IsNullOrEmpty(pageTitle)) {
        title = pageTitle;   
    }
    
    string siteName = Convert.ToString(WorkContext.CurrentSite.SiteName);
}
<!DOCTYPE html> 
<html lang="@WorkContext.CurrentCulture" class="static @Html.ClassForPage()"> 
<head> 
    <meta charset="utf-8" />
    @if (isPageTitleHideSiteName) {
        <title>@title</title> 
    }
    else {
        if (isPageTitleSiteNameLast) {
            <title>@Html.Title(siteName, title)</title> 
        }
        else {
            <title>@Html.Title(title, siteName)</title> 
        }
    }
    @Display(Model.Head)
    <script>(function(d){d.className="dyn"+d.className.substring(6,d.className.length);})(document.documentElement);</script> 
</head> 
<body>
@* Layout (template) is in the Body zone @ the default position (nothing, zero, zilch) *@
@Display(Model.Body)
@Display(Model.Tail)
</body>
</html>